using System;
using System.Threading;

namespace Client
{
	public class Controleur_Scan
	{
		private Thread m_ThreadUpdate;
		private Wait_Scan m_Windows;
		private bool m_IsMaxInfo;
		private Controleur_Collection m_CtrlCollection;
		
		public Controleur_Scan (Controleur_Collection ctrl_Collection) {
			m_IsMaxInfo = false;
			m_Windows = new Wait_Scan ();
			m_CtrlCollection = ctrl_Collection;
		}
		
		public void Start() {
			Gtk.Application.Invoke (delegate {
				m_Windows.Show ();
			});
			
			m_Windows.AddControlleur(this);
			
			m_ThreadUpdate = new System.Threading.Thread((ThreadStart) delegate {
				while(true) {;
					Thread.Sleep(100);
					string message;
					
					if(m_IsMaxInfo)
						message = m_CtrlCollection.Collection.NbFolderInScan + " are scanned.\n\nCurrent path :\n" +
							((m_CtrlCollection.Collection.CurrentfolderScan.Length > 40)? m_CtrlCollection.Collection.CurrentfolderScan.Substring(0, 40) : m_CtrlCollection.Collection.CurrentfolderScan);
					else
						message = m_CtrlCollection.Collection.NbFolderInScan +" are scanned.\n\n\n\n";
					
					m_Windows.Info(message);
				}
			});
			
			m_ThreadUpdate.Start();
		}
		
		
		public void Stop() {
			m_ThreadUpdate.Abort();
			m_Windows.Destroy();
		}
		
		public void ModeInfo() {
			m_IsMaxInfo = !m_IsMaxInfo;
		}
		
		public void Cancel() {
			m_CtrlCollection.CancelScan();
			Stop();
		}
	}
}

